from django.shortcuts import render
from django.http import JsonResponse,HttpResponse
from .utils import getPublicData
from .utils import getCenter,getCenterLeftData,getBottomLeft,getCenterRightData,getCenterChangData,getbottomRight


def center(request):
    if request.method == 'GET':
        sumCar,highVolume,topCar,mostModel,mostBrand,averagePrice = getCenter.getBaseData()
        lastSortList = getCenter.getRollData()
        oilRate,electricRate,mixRate = getCenter.getTyeRate()
        return JsonResponse({
            'sumCar':sumCar,
            'highVolume': highVolume ,
            'topCar':topCar,
            'mostModel':mostModel,
            'mostBrand':mostBrand,
            'averagePrice':averagePrice,
            'lastSortList': lastSortList,
            'oilRate': oilRate,
            'electricRate': electricRate,
            'mixRate':mixRate
        })

def centerLeft(request):
    if request.method == 'GET':
        lastPieList = getCenterLeftData.getPieBrandData()
        return JsonResponse({
            'lastPieList': lastPieList
        })

def bottomLeft(request):
    if request.method == 'GET':
        brandList,volumeList,priceList = getBottomLeft.getSquareData()
        return JsonResponse({
            'brandList':brandList,
            'volumeList':volumeList,
            'priceList':priceList
        })
def centerRight(request):
    if request.method == 'GET':
        realData = getCenterRightData.getpriceSortList()
        return JsonResponse({
            'realData':realData
        })
def centerRightChange(request,energyType):
    if request.method == 'GET':
        oilData,electricData = getCenterChangData.getCircleData()
        realData =[]
        if energyType == 1:
            realData = oilData
        else:
            realData = electricData

        return JsonResponse({
            'realData':realData
        })
def bottomRight(request):
    if request.method == 'GET':
        carData = getbottomRight.getSquareData()
        return JsonResponse({
            'carData':carData
        })